<?php
namespace Pay\Controller;
class AuthController extends PayController
{
	private $data;
	private $sign;
	private $xml;
	public function isAuth()
	{
		
		return true;
		$webconfig=M("Websiteconfig")->find();
		$this->data=array('Com'=>$webconfig['domain'], 'Code'=>$webconfig['serverkey'], 'SignType'=>'md5', );
		
		//echo '<pre/>'; print_r($this->data); exit;
		$this->sign=self::Sign();
		$this->xml=self::getXml();
		$cu=self::reForm();
		$cu=json_decode($cu);
		
		//echo '<pre/>'; print_r($webconfig);exit;
		if($cu->code == 200 && $cu->status == 'success')
		{
			return true;
		}
		return false;
	}
	
	private function getXml(){
		$xml='<xml>';
		foreach($this->data as $tag => $value)
		{
			$xml.="<".$tag.">".$value."</".$tag.">";
		}
		$xml.="<Sign>".$this->sign."</Sign>";
		$xml.="</xml>";
		return $xml;
	}
	
	private function Sign(){
		ksort($this->data);
		$string="";
		foreach($this->data as $k=>$v)
		{
			$string.=$k."=".$v."$";
		}
		$string=substr($string,0,count($string)-2);
		$string=md5($string);
		$string=strtoupper($string);
		return $string;
	}
	private function reForm(){
		//echo C("auth_http")."<br/>";
		//echo '<pre/>'; print_r($this->xml); exit;
		$cu=curl_init();
		curl_setopt($cu,CURLOPT_URL,C("auth_http"));
		curl_setopt($cu,CURLOPT_RETURNTRANSFER,1);
		curl_setopt($cu,CURLOPT_POST,1);
		curl_setopt($cu,CURLOPT_POSTFIELDS,$this->xml);
		$out=curl_exec($cu);
		curl_close($cu);
		$out=json_decode($out,true);
		if($out['code'] == 200 && $out['status'] == 'success')
		{
			return json_encode($out);
		}
		else
		{
			return false;
		}
	}
}